package com.yjc.sunnyweather


import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.os.Handler
import com.gyf.immersionbar.ImmersionBar
import com.yjc.sunnyweather.constant.CommonConstant
import com.yjc.sunnyweather.extension.toast
import com.yjc.sunnyweather.logic.network.ServiceCreator
import com.yjc.sunnyweather.util.CommonUtil
import com.yjc.sunnyweather.util.DataStoreUtil
import com.yjc.sunnyweather.util.LogUtil
import com.yjc.sunnyweather.util.StatusBarUtil


class MainActivity : BaseActivity() {

    private var isExit = false;

    private var mHandler: Handler = CommonUtil.getHandler { isExit = false }

    companion object {
        @JvmStatic
        fun actionStart(context: Context){
            val intent = Intent(context, MainActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)

        StatusBarUtil.immersiveStatusBar(this, Color.TRANSPARENT)
        setContentView(R.layout.activity_main)

        val token = DataStoreUtil.getString(ServiceCreator.BASE_TOKEN_NAME, "")
        if (token.isEmpty()){
            DataStoreUtil.putString(ServiceCreator.BASE_TOKEN_NAME,"eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ4aXV5dSBsaS4iLCJ1c2VyVHlwZSI6IjIiLCJkZXZpY2UiOiJhbmRyb2lkIiwidXNlcklkIjoxLCJpYXQiOjE2NzIwNDg3NzJ9.NqI9kXmBZ-1Jia_4uNH-R8opcxuVNdA8zm6ixjpaifTuAxkjrGMx2VFil37IEUll94TzFz1B8xJTPdlEsmjI4A")
        }

    }

    override fun onBackPressed() {
        LogUtil.w("MainActivity","点击了back,isExit is $isExit")
        if (isExit){
            ActivityCollector.finishAll()
        }else{
            isExit = true
            CommonConstant.backMsg.toast()
            mHandler.sendEmptyMessageDelayed(0,2000)
        }
    }




}